package com.hwadee.JPKC.controller;

import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import com.hwadee.JPKC.entity.courseDeclare;
import com.hwadee.JPKC.entity.courseInfo;
import com.hwadee.JPKC.entity.courseTypeOne;
import com.hwadee.JPKC.entity.courseTypeTwo;
import com.hwadee.JPKC.service.CourseInfoService;
import com.hwadee.JPKC.service.CourseTypeOneService;
import com.hwadee.JPKC.service.CourseTypeTwoService;
import com.hwadee.JPKC.service.courseViewService;

/*
 * 学生与游客主页
 */
@Controller
@RequestMapping("/indexStudent")
public class IndexStudentController {


    @Autowired
    private CourseTypeOneService courseTypeOneService;

    @Autowired
    private CourseTypeTwoService courseTypeTwoService;

    @Autowired
    private CourseInfoService courseInfoService;


    /**
     * 方法：Index 网站访问量
     * @param request
     * @return String
     * @date 2022-02-12
     */
    @RequestMapping("/")
    public String Index(Model model,courseInfo courseInfo,HttpServletRequest request) {
        //网页访问量
        ServletContext context = request.getServletContext();
        /**
         * 从ServletContext中获取计数器对象
         */
        Integer count = (Integer) context.getAttribute("counter");
        /**
         * 如果为空，则在ServletContext中设置一个计数器的属性
         */
        if (count == null) {
            count = 1;
            context.setAttribute("counter", count);
        } else {
            context.setAttribute("counter", count + 1);
        }
        //获得所有栏目1
        List<courseTypeOne> cto=courseTypeOneService.getAll();

        model.addAttribute("cto", cto);
        //获得所有栏目2
        List<courseTypeTwo> cto2=courseTypeTwoService.getAll();

        model.addAttribute("cto2", cto2);
        //热门课程top4
        List<courseInfo> ci = courseInfoService.selectcourseInfosMax();

        model.addAttribute("ci", ci);
        //新上线课程
        List<courseInfo> c = courseInfoService.selectcourseInfoFour("已上线");

        model.addAttribute("c", c);

        return "indexStudent";


    }





}
